<template>
  <div class="admin-container">
    <div style="margin-bottom: 10px;display: flex;align-items: center" v-show="queryType == false">
        <el-input prefix-icon="el-icon-search" placeholder="广告名称" style="width: 200px" v-model="query.title"></el-input>
        <el-button style="margin-left: 10px" icon="el-icon-search" type="primary" @click="submitQuery">查询
        </el-button>
        <el-button style="margin-left: 10px" icon="el-icon-refresh-right" type="info" @click="resetQuery">重置
        </el-button>
      </div>
      <el-table border :data="tableData" style="width: 100%" align="center">
        <el-table-column prop="name" label="企业名称" align="center"> </el-table-column>
        <el-table-column prop="legalPerson" label="法定代表人" align="center"> </el-table-column>
        <el-table-column prop="capital" label="注册资本(万元)" align="center"> </el-table-column>
        <el-table-column prop="linkman" label="负责人" align="center"> </el-table-column>
        <el-table-column prop="phone" label="负责人联系方式" align="center"> </el-table-column>
        <el-table-column label="企业状态" align="center">
          <template slot-scope="scope">
            <div>{{companyStatusFormate("company_status-"+scope.row.status)}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="memo" label="驳回说明" align="center"> </el-table-column>
        <el-table-column fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="viewCompany(scope.row)"
              >查看公司</el-button
            >
            <el-button type="text" size="small" v-permission="['company.audit']" v-if="scope.row.status==1" @click="auditCompany(scope.row)"
              >审核公司</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-footer class="el-footerBox">
        <el-pagination
          background
          layout="prev, pager, next"
          :total="total"
          :page-size="pageSize"
          :current-page.sync="pageNum"
          @current-change="getcompanyList"
        >
        </el-pagination>
      </el-footer>
  </div>
</template>

<script>
import permission from '@/directive/permission/index.js' // 权限判断指令
import utils from "@/utils/utils.js";
import { list as companyList } from "@/api/adminCompany";
import { find as projectFind } from "@/api/project";
import { list as projectActivityList } from "@/api/projectActivity";

export default {
  directives: { permission },
  components: {},
  name: "project",
  data() {
    return {
      queryType:true,
      query:{},
      total:0,
      pageNum:1,
      pageSize:1,
      tableData: [],

      //字典信息
      companyStatusDict:[],
      companyStatusDictPromise:"",
    };
  },
  watch: {
    $route: {
      handler: function (route) {},
      immediate: true,
    },
  },

  created() {
    this.companyStatusDictPromise = utils.getDictList("company_status", (res) => {
      this.companyStatusDict = res.data;
    });
  },

  mounted() {
    let _this = this
    
    Promise.all([this.taxTypeDictPromise, this.registrationDictPromise]).then(
      (res) => {
        //console.log("字典已经全部加载完成--");
        _this.getcompanyList()
      }
    );
  },

  destroyed() {},

  methods: {

    //获取公司列表
    getcompanyList() {
      let _this = this
      let params = new URLSearchParams();
      params.append('pageNum', _this.pageNum);
      params.append('pageSize', _this.pageSize);
      companyList(params)
        .then((res) => {
          console.log("companyList成功获取数据--", res);
          if (res.type == "success") {
            this.tableData = res.data.data;
            this.total = res.data.total
            // if(this.tableData.length > 0){
            //   this.tableData.map(item => {
            //   item.activityDate = utils.dateFormatter(item.activityDate)
            //   item.jb = this.jbFormate(item.jb)
            //   })
            //   }
          }
        })
        .catch((err) => {
          this.$message.error(err.msg);
        });
    },

    //条件查询
    submitQuery(){

    },

    //条件查询
    resetQuery(){

    },


    //查看公司
    viewCompany(data) {
      console.log('data--',data);
      this.$router.push({
        path: "/admin/company/view",
        query: {companyId: data.id },
      });
    },

    //审核公司
    auditCompany(data){
      console.log('data--',data);
      this.$router.push({
        path: "/admin/company/audit",
        query: {companyId: data.id },
      });
    },

    companyStatusFormate(data) {
      return utils.selectDictLabel(this.companyStatusDict, data);
    },
  },
};
</script>

<style lang="scss" scoped>
.admin-container{
  padding: 20px;
}

.el-pagination {
  display:block;
}
</style>
